package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteDictService;
import com.sikaryofficial.system.api.domain.SysDictData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 字典服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteDictFallbackFactory implements FallbackFactory<RemoteDictService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteDictFallbackFactory.class);

    @Override
    public RemoteDictService create(Throwable throwable) {
        log.error("字典服务调用失败:{}", throwable.getMessage());
        return new RemoteDictService() {
            /**
             * 根据类型查询字段数据
             *
             * @param dictType 字典类型
             * @return 结果
             */
            @Override
            public R<List<SysDictData>> dictType(String dictType) {
                return R.fail("根据类型查询字段数据失败:" + throwable.getMessage());
            }
        };
    }
}
